
# first an ODBC connection to MSSQL database server has to be setup
# http://www.time-travellers.org/shane/howtos/MS-SQL-Express-Python-HOWTO.html
#  section Create the ODBC Data Source

import dbi
import odbc

def main(  odbc_conn_name='', 
            queries=['', '']):
    """ 
    - submit list of queries to be launched against odbc connection
    - one single value as a result is expected
    - queries submited as list to reuse odbc connection
    - creating new connection per query would (assumption) be expensive
    """
    conn=odbc.odbc("DSN=%s" % (odbc_conn_name))
    cursor=conn.cursor()
    o = []
    for q in queries:
        try:
            cursor.execute(q)
            o.append(cursor.fetchall()[0][0])
        except:
            o.append(None)
    return o

if __name__ == "__main__":
    ''' '''
    print main(odbc_conn_name='localmssql', 
                queries=    [   
                """ use test
                    select count(1) 
                    from import.Archive_data_Deal_UTF8""", 
                'nonsense query'
                ])